﻿<?php 
	if(!isset($_SESSION)){
		session_start(); 
	} 
?>
<html>
<head>
	<title>Indika Stores</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript" src="./public/js/jquery.js"></script>
    <script type="text/javascript" src="./public/js/jquery-ui.js"></script>
	<script type="text/javascript" src="./public/js/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="./public/js/jquery.validate.js"></script>
	<script type="text/javascript" src="./public/js/jquery.dataTables.js"></script>
	<script type="text/javascript" src="./public/js/TableTools.js"></script>
	<script type="text/javascript" src="./public/js/ZeroClipboard.js"></script>
	
    <link rel="stylesheet" href="./public/css/jquery/jquery-ui.css">
	<link rel="stylesheet" href="./public/css/jquery/data_table.css"/>
	<link rel="stylesheet" href="./public/css/jquery/TableTools.css"/>
	<link rel="stylesheet" href="./public/css/layout.css"/>
	<link rel="stylesheet" href="./public/css/style.css"/>
	
	<script type="text/javascript">
		var dTable;
		$(document).ready(function(){
			$('.datePicker').datepicker({
				dateFormat: 'yy-mm-dd',
				monthNamesShort: ['ජනවාරි','පෙබරවාරි','මාර්තු','අප්‍රේල්','මැයි','ජුනි','ජූලි','අගෝස්තු','සැප්තැම්බර්','ඔක්තෝම්බර්','නොවැම්බර්','දෙසැම්බර්'],
				dayNamesMin: ['ඉරි', 'සඳු', 'අඟ', 'බදා', 'බ්‍රහ', 'සිකු', 'සෙන'],
				changeYear: true,
				changeMonth: true
			});
			
			dTable = $('.dataTable').dataTable({
				"sPaginationType": "full_numbers",
				"iDisplayLength": 11,
				"bDestroy": true,
				"fnDrawCallback": function() {
					if ($('.dataTables_paginate span span.paginate_button').size()){
						$('.dataTables_paginate')[0].style.display = "block";
					} else {
						$('.dataTables_paginate')[0].style.display = "none";
					}
				}
			});
		});
		
	</script>
</head>
<body>
	<div id="wrapperOuter">
		<div id="wrapperInner">
			<?php 
			if(isset($_SESSION['page']) && $_SESSION['page'] != 'index.php'){
			?>
			<div id="wrapper">
				<div id="header">
					<div id="logo"><img src="./public/images/logo.png" height="100px" width = "120px"/></div>
					<div id="headerTitle">
						<div id="title">Shopping System</div>
						<div id="userName"><?php if(isset($_SESSION['userName'])) echo "Welcome ".$_SESSION['userName']; ?></div>
					</div>
			<?php 
				if(isset($_SESSION['userTypeId']) && ($_SESSION['userTypeId'] == "1" || $_SESSION['userTypeId'] == "2" || $_SESSION['userTypeId'] == "3" )){ 
					if((isset($_SESSION['userTypeId']) && $_SESSION['userTypeId'] == "3" || $_SESSION['userTypeId'] == "2") && (isset($_SESSION['userPassword']) && $_SESSION['userPassword'] == "e10adc3949ba59abbe56e057f20f883e" )){ 
			?>					
					<div id="mainMenu">
						<?php include './pages/defaultView.php'; ?>
					</div>
				</div>
				<div id="content">
					<?php include './pages/newProfile.php'; ?>
				</div>
			<?php  
					}else{
			?>
					<div id="mainMenu">
						<?php include './pages/mainMenu.php'; ?>
					</div>
				</div>
				<div id="content">
					<?php include './pages/'.$_SESSION['page']; ?>
				</div>
			<?php 
					}
				}else{ 
					if(isset($_SESSION['userPassword']) && $_SESSION['userPassword'] == "e10adc3949ba59abbe56e057f20f883e"){ 
			?>					
					<div id="mainMenu">
						<?php include './pages/defaultView.php'; ?>
					</div>
				</div>
				<div id="content">
					<?php include './pages/newProfile.php'; ?>
				</div>
			<?php  
					}else{
			?>
					<div id="cashierMainMenu">
						<?php include './pages/cashierMainMenu.php'; ?>
					</div>
				</div>
				<div id="content">
					<?php include './pages/'.$_SESSION['page']; ?>
				</div>
			<?php 
					} 
				} 
			?>
			</div>
			<?php 
			}else{ 
			?>
			<div id="loginFormOuter">
				<div id="header">
					<div id="logo"><img src="./public/images/logo.png"/></div>
					<div id="title">Shopping System</div>
				</div>
				<div id="loginForm" class="webForm">
					<form action="./system/action/login.php" method="POST">
						<table width="100%">
							<tr>
								<td colspan="2">
									<?php
									if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ 
									?>
										<div class="error">
											<?php echo $_SESSION['error']; ?>
										</div>
									<?php 
									} else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){
									?>
										<div class="success">
											<?php echo $_SESSION['success']; ?>
										</div>
									<?php 
									}
									?>
								</td>
							</tr>
							<tr>
								<td>User Name:</td>
								<td><input type="text" name="userName" id="userName"/></td>
							</tr>
								<td>Password:</td>
								<td><input type="password" name="userPassword" id="userPassword"/></td>
							</tr>
								<td colspan="2" align="right">
									<button type="submit" ><img src="public/images/button-img/login.png"/><span> login </span></button>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</div>
			<?php 
			} 
			?>			
		</div> 
	</div>
	<?php
	// Clear previous messages.
	if(isset($_SESSION['error'])) unset($_SESSION['error']);
	if(isset($_SESSION['success'])) unset($_SESSION['success']);
	?>
</body>
</html>
